﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace ZMHWcfServiceLibrary
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的类名“MySingleton”。
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class MySingleton :  IMySingleton, IDisposable
    {
        public int Counter { get; set; } = 0;

        public MySingleton()
        {
            Trace.WriteLine(OperationContext.Current?.SessionId);
            Trace.WriteLine("MySingleton!");
        }
        public void MyMethod()
        {
            Counter++;
            Trace.WriteLine("Counter = " + Counter);
        }
        public void MyOtherMethod()
        {
            Counter++;
            Trace.WriteLine("Counter = " + Counter);
        }
        public void Dispose()
        {
            Trace.WriteLine(OperationContext.Current?.SessionId);
            Trace.WriteLine("Displose!");
        }

        public int GetCount()
        {
            return Counter;
        }
    }
}
